package com.whmskj.xjlhsc.mobie.equipment.controller;

import com.whmskj.xjlhsc.controller.vo.Result;
import com.whmskj.xjlhsc.entity.WbRecord;
import com.whmskj.xjlhsc.enums.ScEnums;
import com.whmskj.xjlhsc.mobie.equipment.controller.fo.ApproveListFo;
import com.whmskj.xjlhsc.service.WbRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @BelongsProject: XJLHSC
 * @BelongsPackage: com.whmskj.xjlhsc.mobie.controller
 * @Author: lk
 * @CreateTime: 2025-06-24
 * @Description: TODO
 * @Version: 1.0
 */
@RestController
@RequestMapping("/mob/maintenanceAppral")
@Slf4j
@RequiredArgsConstructor
@Tag(description = "维保审核列表接口", name = "维保审核列表接口")
public class MaintenanceApproveController {

    private final WbRecordService wbRecordService;

    /**
     * 查询维保审核列表
     * @param fo
     * @return
     */
    @GetMapping("/getApproveList")
    @Operation(description = "查询维保审核列表")
    public Result getApproveList(ApproveListFo fo) {
        return Result.success(wbRecordService.getApproveList(fo));
    }

    /**
     * 查询维保审核详情
     * @param recordId
     * @return
     */
    @GetMapping("/getApproveDetail/{recordId}")
    @Operation(description = "查询维保审核详情")
    public Result getApproveDetail(@PathVariable Long recordId) {
        return Result.success(wbRecordService.getApproveDetail(recordId));
    }

    /**
     * 维保审核
     * @param wbRecord
     * @return
     */
    @PostMapping("/approve")
    @Operation(description = "维保审核")
    public Result approve(@RequestBody WbRecord wbRecord) {
        if (ScEnums.SCWBSHZT.APPED.getCode() == (wbRecord.getWbShState())) {
            wbRecord.setWbRecordState(ScEnums.SCWBJLZT.COMPLETED.getCode());
            wbRecord.setWbTjState(ScEnums.SCWBTJZT.PROCESSED.getCode());
            wbRecord.setWbJdState(ScEnums.SCWBJDZT.PASS.getCode());
        }else {
            wbRecord.setWbRecordState(ScEnums.SCWBJLZT.REJECTED.getCode());
            wbRecord.setWbTjState(ScEnums.SCWBTJZT.IN_MAINTENANCE.getCode());
            wbRecord.setWbJdState(ScEnums.SCWBJDZT.REJECTED.getCode());
        }
        return Result.success(wbRecordService.update(wbRecord));
    }
}
